﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Simple.Service;
using Simple.ViewModel;
using Simple.Common.Infrastructure;
using Autofac;
using System.Text;
using Simple.Web.Framework.Infrastructure;
using Simple.Web.Framework.Infrastructure.Aop;

namespace HBootStrap.Admin.Controllers
{
    [LoginAuthorize]
    [SafeCheckFilter]
    [ModelStateFilter]
    public class BaseController : Controller
    {
        protected CacheService _cacheService = EngineContext.Current.Resolve<CacheService>();

        /// <summary>
        /// 重写返回json的方法
        /// </summary>
        /// <param name="data"></param>
        /// <param name="contentType"></param>
        /// <param name="contentEncoding"></param>
        /// <param name="behavior"></param>
        /// <returns></returns>
        protected override JsonResult Json(object data, string contentType,
                 Encoding contentEncoding, JsonRequestBehavior behavior)
        {
            if (behavior == JsonRequestBehavior.DenyGet
                && string.Equals(this.Request.HttpMethod, "GET",
                                 StringComparison.OrdinalIgnoreCase))
                return new JsonResult();
            return new JsonNetResult()
            {
                Data = data,
                ContentType = contentType,
                ContentEncoding = contentEncoding,
                JsonRequestBehavior = behavior
            };
        }
    }
}
